package com.bw.culture.adapter

import android.graphics.drawable.Icon
import android.media.Image
import android.net.Uri
import android.view.LayoutInflater
import android.view.View.OnClickListener
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bw.culture.R
import com.bw.culture.databinding.ImageItemBinding
import com.bw.culture.onclick.ClickListener
import java.net.URI
import kotlin.coroutines.coroutineContext

class ImageAdapter(private val image:MutableList<String>,private val uri:MutableList<Uri>) : RecyclerView.Adapter<ImageAdapter.ImageViewHolder>() {


//    override fun getItemViewType(position: Int): Int {
//
//    }

    private var onClick:ClickListener ? = null


    fun setItemOnClickListener(listener:ClickListener){
        this.onClick=listener
    }

    inner class ImageViewHolder(val binding:ImageItemBinding):RecyclerView.ViewHolder(binding.root){

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImageViewHolder {
        val itemBinding = ImageItemBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return ImageViewHolder(itemBinding)
    }

    override fun getItemCount(): Int {
        return image.size
    }

    override fun onBindViewHolder(holder: ImageViewHolder, position: Int) {
        if(image[position]=="+"){
            if(image.size<10){
                holder.binding.ic.setImageResource(com.bw.common.R.drawable.add_img)
            }

        }else{
            Glide.with(holder.itemView.context).load(uri[position]).into(holder.binding.ic)
        }

        holder.binding.ic.setOnClickListener {
            onClick?.onClick(position)
        }
    }
}